package com.kgis.map.rule {
   import com.kgis.map.common.basetype.hashmap.HashMap;
   import com.kgis.map.common.util.Evals;
   import com.kgis.map.rule.IRule;
   import com.kgis.map.style.StyleRule;
   
   import flash.utils.Dictionary;
   
   import mx.collections.ArrayCollection;

   /**
    * 规则
    * 支持样式规则、标注规则
    */
   public class Rule implements IRule {
      /**规则条件数组，(filter条件,object)*/
      private var _expressionFilterDic:ArrayCollection;
	 //暂时为hashmap
	  private var _styleMap:HashMap;

      public function Rule(filterDic:ArrayCollection = null) {
         _expressionFilterDic = filterDic;
      }

      /**
       * 根据fieldsMap以及expressionFilterDic获取满足条件的style或label
       */
      public function getRightStyle(fieldsMap:Object):Object {
         if (!fieldsMap) {
            return null;
         }

         //遍历dictionary，满足条件就退出
         for each(var key:StyleRule in expressionFilterDic) {
            if (Evals.evalToBoolean(fieldsMap, key.filter)) {
               return key.style;
            }
         }
         return null;
      }
	  
	  /**
	   * 根据fieldsMap以及expressionFilterDic获取满足条件的style或label
	   */
	  public function getRightLabel(fieldsMap:Object):Object {
		  if (!fieldsMap) {
			  return null;
		  }
		  
		  //遍历dictionary，满足条件就退出
		  for each(var key:StyleRule in expressionFilterDic) {
			  if (Evals.evalToBoolean(fieldsMap, key.filter)) {
				  return key.label;
			  }
		  }
		  return null;
	  }

      public function get expressionFilterDic():ArrayCollection {
         return _expressionFilterDic;
      }

      /**
       * @private
       */
      public function set expressionFilterDic(value:ArrayCollection):void {
         _expressionFilterDic = value;
      }

      public function clone():IRule {
         return new Rule(this.expressionFilterDic);
      }

   }
}